﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/layui/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <title>会员等级管理</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }

        .layui-form-item {
            padding: 10px 0px;
            margin-bottom: -20px;
        }
    </style>
</head>
<body>
    <div>
        <script type="text/html" id="barDemo">
            <div class="layui-btn-container">
                <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe654;新增</i></button>
                <button type="button" lay-event="update" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;修改</i></button>
                <button type="button" lay-event="delete" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe640;删除</i></button>
                <button type="button" lay-event="assign"  class="layui-btn  layui-btn-sm"><i class="layui-icon">&#xe605;分配管理员</i></button>
            </div>
        </script>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">店铺名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="Name">
                </div>
                <label class="layui-form-label">联系人：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="ContactName">
                </div>
                <label class="layui-form-label">店铺地址：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="Address">
                </div>
                <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;查询</i></button>
            </div>
        </form>

        <table class="layui-inline" lay-filter="table" id="cardList"></table>
    </div>
    <script>
        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;


            //搜索按钮的点击事件
            $('#searh').on('click', function () {
                //获取输入框的值
                var Name = $('#Name').val();
                var ContactName = $('#ContactName').val();
                var Address = $('#Address').val();

                //表格重载，并传回服务器参数
                table.reload('cardList', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        'Name': Name,
                        'ContactName': ContactName,
                        'Address': Address
                    }
                });
            });
            //载入表格
            table.render({
                elem: '#cardList',
                toolbar: '#barDemo',
                //filter: 显示筛选图标 exports: 显示导出图标 print: 显示打印图标
                defaultToolbar: ['filter', 'print', 'exports'],
                url: '/Shops/GetShopList',

                //开启分页
                page: 'true',
                cols: [
                    [{
                        type: 'checkbox'
                    }, {
                        field: 'S_ID',
                        width: 150,
                        title: '店铺编号',
                        sort: true
                    },
                    {
                        field: 'S_Name',
                        width: 150,
                        title: '店铺名称',
                        sort: true
                    },
                    {
                        field: 'S_Category',
                        width: 150,
                        title: '店铺类型',
                        sort: true
                    },
                    {
                        field: 'S_ContactName',
                        width: 150,
                        title: '联系人',
                        sort: true
                    },
                    {
                        field: 'S_ContactTel',
                        width: 150,
                        title: '联系电话',
                        sort: true,
                    },
                    {
                        field: 'S_Address',
                        width: 330,
                        title: '地址',
                        sort: true,
                    },
                    {
                        field: 'S_Remark',
                        width: 150,
                        title: '备注',
                        sort: true,
                    },
                    {
                        field: 'S_IsHasSetAdmin',
                        width: 150,
                        title: '是否已分配管理员',
                        sort: true,
                    },
                    {
                        field: 'S_CreateTime',
                        width: 150,
                        title: '加盟时间',
                        sort: true,
                        templet: function (d) { return FormatToDate(d.S_CreateTime) }
                    }
                    ]
                ]
            });
            //转换日期方法
            function FormatToDate(val) {
                if (val != null) {
                    var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
                    //月份为0-11，所以+1，月份小于10时补个0
                    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                    return date.getFullYear() + "-" + month + "-" + currentDate;
                }
                return "";
            }
            //监听事件
            table.on('toolbar(table)', function (obj) {
                //遍历数组
                var checkStatus = table.checkStatus(obj.config.id).data;
                switch (obj.event) {
                    case 'add':
                        layer.open({
                            type: 2,
                            content: ['/Shops/AddShopList', 'no'],
                            area: ['500px', '600px'],
                            offset: ['100px', '400px'],
                            skin: 'layui-layer-molv',
                            maxmin: true,
                            //刷新页面
                            end: function () { table.reload('cardList') }
                        });
                        break;
                    case 'delete':
                        if (checkStatus[0] != null) {
                            var S_ID = checkStatus[0].S_ID;
                            layer.confirm('您确定要删除id为' + S_ID + "的店铺吗", function (index) {
                                $.ajax({
                                    type: "post",
                                    url: "/Shops/Del",
                                    data: { S_ID: S_ID },
                                    success: function (data) {
                                        if (data.code == 0) {
                                            parent.layer.msg(data.msg, { icon: 1 });
                                            table.reload('cardList');
                                            obj.config.id.del();
                                        } else {
                                            parent.layer.msg(data.msg, { icon: 5 });
                                        }
                                    }
                                })
                                layer.close(index);
                            });
                        } else {
                            layer.msg("请选择一行数据", { icon: 7 });
                        }
                        break;
                    case 'update':
                        if (checkStatus[0] != null) {
                                var S_ID = checkStatus[0].S_ID;
                                layer.open({
                                    type: 2,
                                    content: ['/Shops/UpdeShop/' + S_ID + '', 'no'],
                                    area: ['500px', '600px'],
                                    offset: ['100px', '400px'],
                                    skin: 'layui-layer-molv',
                                    maxmin: true,
                                    //弹窗关闭刷新列表
                                    end: function () { table.reload('cardList') }
                                });

                        } else {
                               layer.msg("请选择一行数据", { icon: 7 });
                        }
                        break;
                    case 'assign':
                          if (checkStatus[0] != null) {
                            var S_ID = checkStatus[0].S_ID;
                                $.ajax({
                                    type: "post",
                                    url: "/Shops/PanDuan/",
                                    data: { S_ID: S_ID },
                                    success: function (data) {
                                        if (data.code == 0) {
                                             layer.open({
                                                type: 2,
                                                content: ['/Shops/Assign/' + S_ID + '', 'no'],
                                                area: ['500px', '600px'],
                                                offset: ['100px', '400px'],
                                                skin: 'layui-layer-molv',
                                                maxmin: true,
                                                //弹窗关闭刷新列表
                                                end: function () { table.reload('cardList') }
                                            }); 
                                        } else {
                                            parent.layer.msg(data.msg, { icon: 5 });
                                        }
                                    }
                                })
                         
                        } else {
                            layer.msg("请选择一行数据", { icon: 7 });
                        }
                        break;
                };
            });

        })

    </script>
</body>
</html>

